Programming Questions for Practice
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/*
Given an integer array nums, return true if any value appears at least
twice in the array, and return false if every element is distinct.
*/
bool containsDuplicate(int* nums, int numsSize){
int i, j;
for(i = 0; i < numsSize; i++) {
for(j = i+1; j < numsSize; j++) {
if(nums[i] == nums[j])
return true;
}
}
return false;
}
int main()
{
int nums[] = {1,2,3,4};
bool result;
result = containsDuplicate(nums, 4);
printf(result?"true":"false");
return 0;
}